<template>
     <van-button
          v-if="Show"
          :loading="isFollowLoading"
            class="follow-btn"
            type="info"
            color="#3296fa"
            round
            size="small"
            icon="plus"
            @click="btn"
          >关注</van-button>
          <van-button
          :loading="isFollowLoading"
          v-else
            class="follow-btn"
            round
            size="small"
             @click="btn"
          >已关注</van-button>
</template>

<script>
import { addFollow, deleteFollow } from '@/api/user.js'
export default {
  props: {
    Show: {
      type: Boolean,
      required: true
    },
    user_id: {
      type: [Number, String, Object],
      required: true
    }
  },
  data () {
    return {
      isFollowLoading: false
    }
  },
  methods: {
    async btn () {
      this.isFollowLoading = true
      try {
        if (this.Show) {
          const userId = this.user_id
          await addFollow(userId)
          this.$toast.success('关注成功')
          this.$emit('update-follow', !this.Show)
        } else {
          const userId = this.user_id
          await deleteFollow(userId)
          this.$toast.success('取消关注')
          this.$emit('update-follow', !this.Show)
        }
      } catch (err) {
        this.$toast.fail('操作失败')
      }
      this.isFollowLoading = false
    }
  }
}
</script>

<style>

</style>
